# -*- coding: utf-8 -*-
"""
@ auth : carl_DJ
@ time : 2020-9-23
"""

from locust import TaskSet, task, HttpUser, constant, LoadTestShape


class UserTask(TaskSet):
    @task
    def test_visit(self):
        with self.client.get(url='/s?wd=apple', catch_response=True) as response:
            assert response.status_code == 200
            if response.status_code == 200:
                try:
                    response.elapsed.microseconds <= 500000  # 微秒
                except:
                    response.failure("Timeout")
            else:
                response.failure("Failed!")


class WebsiteUser(HttpUser):
    host = 'http://www.baidu.com'
    task_set = task(UserTask)
    wait_time = constant(1)


